package com.ruoyi.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.equipment.domain.CampusEquipment;
import com.ruoyi.equipment.service.ICampusEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 后勤设备Controller
 * 
 * @author ruoyi
 * @date 2025-05-03
 */
@RestController
@RequestMapping("/equipment/equipment")
public class CampusEquipmentController extends BaseController
{
    @Autowired
    private ICampusEquipmentService campusEquipmentService;

    /**
     * 查询后勤设备列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CampusEquipment campusEquipment)
    {
        startPage();
        List<CampusEquipment> list = campusEquipmentService.selectCampusEquipmentList(campusEquipment);
        return getDataTable(list);
    }

    /**
     * 导出后勤设备列表
     */
    @Log(title = "后勤设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampusEquipment campusEquipment)
    {
        List<CampusEquipment> list = campusEquipmentService.selectCampusEquipmentList(campusEquipment);
        ExcelUtil<CampusEquipment> util = new ExcelUtil<CampusEquipment>(CampusEquipment.class);
        util.exportExcel(response, list, "后勤设备数据");
    }

    /**
     * 获取后勤设备详细信息
     */
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return success(campusEquipmentService.selectCampusEquipmentByEquipmentId(equipmentId));
    }

    /**
     * 新增后勤设备
     */
    @Log(title = "后勤设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampusEquipment campusEquipment)
    {
        return toAjax(campusEquipmentService.insertCampusEquipment(campusEquipment));
    }

    /**
     * 修改后勤设备
     */
    @Log(title = "后勤设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampusEquipment campusEquipment)
    {
        return toAjax(campusEquipmentService.updateCampusEquipment(campusEquipment));
    }

    /**
     * 删除后勤设备
     */
    @Log(title = "后勤设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentIds)
    {
        return toAjax(campusEquipmentService.deleteCampusEquipmentByEquipmentIds(equipmentIds));
    }
}
